package io.github.codelifeleno.jdbrelease.model;

import cn.hutool.core.date.DateUtil;

import java.util.Objects;
import java.util.StringJoiner;

/**
 * JDBRELEASE_LOCK
 * 数据对象映射
 */
public class LockModel {
    private String fileType;
    private String id;
    private String fileName;
    private String isRollback;
    private String isRepeatable;
    private String filePath;

    @Override
    public String toString() {
        return new StringJoiner(", ", LockModel.class.getSimpleName() + "[", "]")
                .add("fileType='" + fileType + "'")
                .add("id='" + id + "'")
                .add("fileName='" + fileName + "'")
                .add("isRollback='" + isRollback + "'")
                .add("isRepeatable='" + isRepeatable + "'")
                .add("filePath='" + filePath + "'")
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;

        LockModel lockModel = (LockModel) o;
        return Objects.equals(getFileType(), lockModel.getFileType()) && Objects.equals(getId(), lockModel.getId()) && Objects.equals(getFileName(), lockModel.getFileName()) && Objects.equals(getIsRollback(), lockModel.getIsRollback()) && Objects.equals(getIsRepeatable(), lockModel.getIsRepeatable()) && Objects.equals(getFilePath(), lockModel.getFilePath());
    }

    @Override
    public int hashCode() {
        int result = Objects.hashCode(getFileType());
        result = 31 * result + Objects.hashCode(getId());
        result = 31 * result + Objects.hashCode(getFileName());
        result = 31 * result + Objects.hashCode(getIsRollback());
        result = 31 * result + Objects.hashCode(getIsRepeatable());
        result = 31 * result + Objects.hashCode(getFilePath());
        return result;
    }

    public String getFileType() {
        return fileType;
    }

    public String getId() {
        return id;
    }

    public String getFileName() {
        return fileName;
    }

    public String getIsRollback() {
        return isRollback;
    }

    public String getIsRepeatable() {
        return isRepeatable;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFileType(String fileType) {
        this.fileType = fileType;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public void setIsRollback(String isRollback) {
        this.isRollback = isRollback;
    }

    public void setIsRepeatable(String isRepeatable) {
        this.isRepeatable = isRepeatable;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public LockModel() {
    }

    public LockModel(String fileType, String id, String fileName, String isRollback, String isRepeatable, String filePath) {
        this.fileType = fileType;
        this.id = id;
        this.fileName = fileName;
        this.isRollback = isRollback;
        this.isRepeatable = isRepeatable;
        this.filePath = filePath;
    }

    /**
     * 根据对象处理，将对象提供给 HIS
     * @return 一个 历史对象
     */
    public HisModel toHisModel() {
        HisModel hisModel = new HisModel();
        hisModel.setFileType(fileType);
        hisModel.setId(id);
        hisModel.setFileName(fileName);
        hisModel.setIsRollback(isRollback);
        hisModel.setIsRepeatable(isRepeatable);
        hisModel.setFilePath(filePath);
        hisModel.setIsOver("1");
        hisModel.setOverTime(DateUtil.formatDateTime(DateUtil.date()));
        return hisModel;
    }
}
